package com.example.tse.rbhttpservice.service.member;


import android.content.Context;

import com.example.tse.rbhttpservice.service.HttpService;
import com.example.tse.rbhttpservice.service.RemoteServiceListenerT;
import com.example.tse.rbhttpservice.service.ResponseServiceListenerT;
import com.example.tse.rbhttpservice.service.RudderResponse;
import com.example.tse.rbhttpservice.service.member.model.MemberGetFollowList;
import com.example.tse.rbhttpservice.service.member.model.MemberGetFollowListRequest;
import com.example.tse.rbhttpservice.service.member.model.MemberGetFollowListResponse;
import com.example.tse.rbhttpservice.service.member.model.MemberGetFollowedList;
import com.example.tse.rbhttpservice.service.member.model.MemberGetFollowedListRequest;
import com.example.tse.rbhttpservice.service.member.model.MemberGetFollowedListResponse;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.kymjs.kjframe.http.HttpParams;

import java.lang.reflect.Type;
import java.util.List;


/**
 * 
 * @author wliu
 *    edi  tse
 */
public class MemberServiceImpl implements MemberService {
	private Context context;
	private static Gson gson = new Gson();
	
	
	public MemberServiceImpl(Context context) {
		this.context = context;
	}
	/**
	 * 获取我的关注列表
	 * @param request
	 * @param listener
	 * @return MemberGetFollowListResponse
	 */		
	 
	    public void getFollowList(MemberGetFollowListRequest request, final RemoteServiceListenerT<MemberGetFollowListResponse> listener) {

        final HttpParams params = new HttpParams();
        


        final String url = "member/getFollowList";


        
        /**
        member
        getFollowList
        GetFollowList
        获取我的关注列表
        GET
        Member
        MemberGetFollowList
        member/getFollowList
        array
        */
	
           final Type type = new TypeToken<List<MemberGetFollowList>>() {
        }.getType();



            new HttpService().getList(context, url, params, MemberGetFollowListResponse.class, new ResponseServiceListenerT<RudderResponse>() {

             @Override
             public void onPreStart() {
                 super.onPreStart();
                 listener.PreStart();
             }

             @Override
             public void ok(RudderResponse rudderResponse) {
                 super.ok(rudderResponse);
                 List<MemberGetFollowList> items = gson.fromJson(rudderResponse.getBody(), type);
                 MemberGetFollowListResponse responce = new MemberGetFollowListResponse();
                 responce.setGetFollowList(items);
                 listener.ok(responce);
             }

             @Override
             public void okData(RudderResponse rudderResponse) {
                 super.okData(rudderResponse);

                 if (rudderResponse == null) {
                     listener.okData(new MemberGetFollowListResponse());
                 } else {
                     List<MemberGetFollowList> items = gson.fromJson(rudderResponse.getBody(), type);
                     MemberGetFollowListResponse responce = new MemberGetFollowListResponse();
                     responce.setGetFollowList(items);
                     listener.okData(rudderResponse == null ? new MemberGetFollowListResponse() : responce);
                 }
             }

             @Override
             public void okData(RudderResponse rudderResponse, int fromWhere) {
                 super.okData(rudderResponse, fromWhere);


                 if (rudderResponse == null) {
                     listener.okData(new MemberGetFollowListResponse(), fromWhere);
                 } else {
                     List<MemberGetFollowList> items = gson.fromJson(rudderResponse.getBody(), type);
                     MemberGetFollowListResponse responce = new MemberGetFollowListResponse();
                     responce.setGetFollowList(items);
                     listener.okData(rudderResponse == null ? new MemberGetFollowListResponse() : responce, fromWhere);
                 }


             }

             @Override
             public void onFailure(int errorNo, String strMsg) {
                 super.onFailure(errorNo, strMsg);
                 listener.failue(errorNo, strMsg);
             }

             @Override
             public void onFinish() {
                 super.onFinish();
                 listener.Finish();
             }
         });
    }            
        
        

   
	
	
	/**
	 * 获取我的粉丝列表
	 * @param request
	 * @param listener
	 * @return MemberGetFollowedListResponse
	 */		
	 
	    public void getFollowedList(MemberGetFollowedListRequest request, final RemoteServiceListenerT<MemberGetFollowedListResponse> listener) {

        final HttpParams params = new HttpParams();
        


        final String url = "member/getFollowedList";


        
        /**
        member
        getFollowedList
        GetFollowedList
        获取我的粉丝列表
        GET
        Member
        MemberGetFollowedList
        member/getFollowedList
        array
        */
	
           final Type type = new TypeToken<List<MemberGetFollowedList>>() {
        }.getType();



            new HttpService().getList(context, url, params, MemberGetFollowedListResponse.class, new ResponseServiceListenerT<RudderResponse>() {

             @Override
             public void onPreStart() {
                 super.onPreStart();
                 listener.PreStart();
             }

             @Override
             public void ok(RudderResponse rudderResponse) {
                 super.ok(rudderResponse);
                 List<MemberGetFollowedList> items = gson.fromJson(rudderResponse.getBody(), type);
                 MemberGetFollowedListResponse responce = new MemberGetFollowedListResponse();
                 responce.setGetFollowedList(items);
                 listener.ok(responce);
             }

             @Override
             public void okData(RudderResponse rudderResponse) {
                 super.okData(rudderResponse);

                 if (rudderResponse == null) {
                     listener.okData(new MemberGetFollowedListResponse());
                 } else {
                     List<MemberGetFollowedList> items = gson.fromJson(rudderResponse.getBody(), type);
                     MemberGetFollowedListResponse responce = new MemberGetFollowedListResponse();
                     responce.setGetFollowedList(items);
                     listener.okData(rudderResponse == null ? new MemberGetFollowedListResponse() : responce);
                 }
             }

             @Override
             public void okData(RudderResponse rudderResponse, int fromWhere) {
                 super.okData(rudderResponse, fromWhere);


                 if (rudderResponse == null) {
                     listener.okData(new MemberGetFollowedListResponse(), fromWhere);
                 } else {
                     List<MemberGetFollowedList> items = gson.fromJson(rudderResponse.getBody(), type);
                     MemberGetFollowedListResponse responce = new MemberGetFollowedListResponse();
                     responce.setGetFollowedList(items);
                     listener.okData(rudderResponse == null ? new MemberGetFollowedListResponse() : responce, fromWhere);
                 }


             }

             @Override
             public void onFailure(int errorNo, String strMsg) {
                 super.onFailure(errorNo, strMsg);
                 listener.failue(errorNo, strMsg);
             }

             @Override
             public void onFinish() {
                 super.onFinish();
                 listener.Finish();
             }
         });
    }            
        
        

   
	
	
}